package com.jlu.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {

  @GetMapping("demo")
  @HystrixCommand(defaultFallback = "defaultFallBack") //熔断之后的处理
  public String demo(Integer id){
    System.out.println("demo is ok");
    if(id<=0){
      throw new RuntimeException("无效id");
    }
    return "demo is ok!!!";
  }

//  默认方案
  public String defaultFallBack(){
    return "这是一个默认方案";
  }

//  备选方案
  public String demoFallBack(Integer id){
    return "当前活动过于火爆，服务已被熔断";
  }
}
